﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2022 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Core;

/// <summary>
/// 缓存服务
/// </summary>
public interface ISysCacheService
{
    /// <summary>
    /// 刷新缓存
    /// </summary>
    /// <param name="type">缓存类型</param>
    /// <returns></returns>
    Task<dynamic> RefreshCache(string type = "");

    /// <summary>
    /// 获取 实体的全部数据
    /// </summary>
    /// <typeparam name="TEntity">数据库表</typeparam>
    /// <returns></returns>
    Task<List<TEntity>> GetListAsync<TEntity>(bool isRefresh = false) where TEntity : class, IPrivateEntity, new();

    #region menu

    /// <summary>
    /// 获取后台左侧菜单列表
    /// </summary>
    /// <param name="area">区域</param>
    /// <returns></returns>
    Task<List<PearMenuItem>> GetMenus(string area);

    #endregion menu

    #region DataConfig

    /// <summary>
    /// 查询一条
    /// </summary>
    /// <param name="id">ID</param>
    Task<TEntity> GetDataConfig<TEntity>(int id);

    /// <summary>
    /// 查询指定父级的所有下级
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <param name="pkey">父级key</param>
    /// <returns></returns>
    Task<List<TEntity>> GetDataConfigEntitiesByPKey<TEntity>(string pkey);

    /// <summary>
    /// 根据key获取指定对象
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <param name="pkey">父级key</param>
    /// <param name="key">key</param>
    /// <returns></returns>
    Task<TEntity> GetDataConfigByKey<TEntity>(string pkey, string key);

    /// <summary>
    /// 获取系统设置
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    /// <param name="pkey">父级Key</param>
    /// <returns></returns>
    Task<TEntity> GetSetting<TEntity>(string pkey) where TEntity : new();

    #endregion DataConfig

    #region Role

    ///// <summary>
    ///// 获取角色列表或获取并刷新
    ///// </summary>
    ///// <param name="isRefresh"></param>
    ///// <returns></returns>
    //Task<List<SysRole>> GetListByRoleAsync(bool isRefresh = false);

    #endregion Role

    #region User 不用

    ///// <summary>
    ///// 查询所有用户
    ///// </summary>
    ///// <returns></returns>
    //Task<List<SysUser>> GetListByUserAsync(bool isrefresh = false);

    #endregion User 不用

    #region 管理用户登陆

    /// <summary>
    /// 获取登陆的管理员用户
    /// </summary>
    /// <param name="userid"></param>
    /// <returns></returns>
    Task<SysUser> GetLoginAdminUser();

    /// <summary>
    /// 刷新登陆管理用户缓存
    /// </summary>
    /// <param name="userid"></param>
    /// <returns></returns>
    Task RefreshLoginAdminUserCache(int userid);

    /// <summary>
    /// 移除登陆管理用户缓存
    /// </summary>
    /// <param name="userids"></param>
    /// <returns></returns>
    Task RemoveLoginAdminUserCache(List<int> userids);

    /// <summary>
    /// 移除登陆管理用户缓存
    /// </summary>
    /// <param name="userid"></param>
    /// <returns></returns>
    Task RemoveLoginAdminUserCache(int userid);

    /// <summary>
    /// 设置登陆管理用户缓存
    /// </summary>
    /// <param name="user"></param>
    /// <returns></returns>
    Task SetLoginAdminUserCache(SysUser user);

    /// <summary>
    /// 设置登陆管理用户缓存
    /// </summary>
    /// <param name="userId"></param>
    /// <returns></returns>
    Task SetLoginAdminUserCache(int userId);

    /// <summary>
    /// 验证权限
    /// </summary>
    ///  <param name="permissionType">权限类型</param>
    /// <param name="controller"></param>
    /// <param name="action"></param>
    /// <param name="userid"></param>
    /// <returns></returns>
    Task<bool> HasAuthorize(string permissionType, string controller, string action, int userid = 0);

    #endregion 管理用户登陆

    #region EmailSendConfig 邮箱发送配置

    /// <summary>
    /// 查询出指定邮箱的邮箱配置
    /// </summary>
    /// <param name="emailAccount">邮箱账号</param>
    /// <returns></returns>
    Task<EmailSendConfig> GetEmailSendConfig(string emailAccount);

    #endregion EmailSendConfig 邮箱发送配置
}